package com.util
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BitmapDataChannel;
    import flash.display.Sprite;
    import flash.filters.DisplacementMapFilter;
    import flash.filters.DisplacementMapFilterMode;
    import flash.geom.Point;
    
    import sekati.display.Canvas;
	
	public class EcholenTransform 
	{
		public var bgColor:uint     = 0xFFCC00;
        public var size:uint        = 200;
        public var offset:uint      = 90;       
        
		public function EcholenTransform()
		{
		}
		
		public function createBitmapData(sWidth:Number,sHeight:Number):BitmapData {			
			var bitmapData:BitmapData = new BitmapData(sWidth, sHeight);
			trace(sWidth+"   "+sHeight);
			for (var y:int = 0; y < sHeight; ++y)
			{
				var yr:Number = y / sHeight; // ratio of Y coordinate to image height
				
				
				var yc:Number = -Math.round(yr * 0x80)+0x80  << 8; // map's Y component
				
				for (var x:int = 0; x < sWidth; ++x)
				{
					var xr:Number = x / sWidth; // ratio of X coordinate to image width
					
					var xc:Number = -Math.round(xr * 0x80)+0x80; // map's X component
					
					bitmapData.setPixel(x, y, yc | xc);
				}
			}
			Canvas.stage.addChild(new Bitmap(bitmapData));
			return bitmapData;

        }
        
        public function createPerlinNoiseBD(sWidth:Number,sHeight:Number):BitmapData{
        	trace("in");
        	var bitmapData:BitmapData = new BitmapData(sWidth, sHeight, true, bgColor);           
            bitmapData.perlinNoise(300,30,2,50,false,false,1,true, null);
			var seed:Number = Math.floor(Math.random() * 10);
			var channels:uint = BitmapDataChannel.GREEN | BitmapDataChannel.BLUE
			bitmapData.perlinNoise(100, 80, 6, seed, false, true, channels, false, null);		
			Canvas.stage.addChild(new Bitmap(bitmapData));	
            return bitmapData;
        }
        
        public function getBitmapFilter(src:Sprite):DisplacementMapFilter {
        	var srcWidth:Number=src.width;
        	var srcHeight:Number=src.height;
            var mapBitmap:BitmapData = createBitmapData(srcWidth,srcHeight);
            return new DisplacementMapFilter(mapBitmap, null, 4, 2, srcWidth,srcHeight, "color", 0x000000);

           /* 
            var mapPoint:Point       = new Point(0, 0);
            var channels:uint        = BitmapDataChannel.RED;
            var componentX:uint      = BitmapDataChannel.RED;
            var componentY:uint      = BitmapDataChannel.BLUE;
            var scaleX:Number        = 0.5;
            var scaleY:Number        = 0.5;
            var mode:String          = DisplacementMapFilterMode.CLAMP;
            var color:uint           = 0;
            var alpha:Number         = 0;
            return new DisplacementMapFilter(mapBitmap,
                                             mapPoint,
                                             componentX,
                                             componentY,
                                             scaleX,
                                             scaleY,
                                             mode,
                                             color,
                                             alpha);*/

        }        


	}
}